require("../util.js");
require("../component/components.js");
require("../component/carouselsPage.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
var vm = new Vue({
    el:"#history",
    data:{
        type:"1",
        pageNumber:1,
        historyList:{},
        historyList1:[],
        historyList2:[]
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.type=this.searchObject&&this.searchObject.type;
        if(!this.type){
            this.getHistoryList();
        }

    },
    methods:{
        //后退
        getBack: function () {
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //历史记录列表
        getHistoryList:function(){
            var that=this;
            if(!userInfo){
                location.href="/loginIndex"
            }
            var data={
                loginUid:userInfo.loginUid,
                pageNumber:that.pageNumber
            };
            this.ajax({url:"/happyi/getHistoryList",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.historyList=b.json.data;
                    that.historyList1=that.historyList.list;
                    if(that.historyList.pageNumber>1){
                        if(that.historyList.list.length>0) {
                            that.historyList2 = that.historyList2.concat(b.json.data.list);
                        }
                    }else{
                        that.historyList2= that.historyList1;
                    }
                }else{
                    that.historyList={};
                    that.historyList1=[];
                    that.historyList2=[];
                    vm.$refs.prompt.toast("获取列表失败！")
                }
            });
        },
        getNext:function(item){
            if(item.type==1){   // 1自媒体 2企业广告3城市广告4传统文化
                location.href="/see/selfMediaVd?id="+item.id+"&uid="+userInfo.id+"&sourceType=1";
            }else if(item.type==2){
                location.href="/see/adDetails?id="+item.id+"&uid="+item.uid;
            }else if(item.type==3){
                location.href="/cityAd/cityAdVideo?cityAdvId="+item.id;
            }else if(item.type==4){

            }
        }

    },
    watch: {

    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    var loadFlag = vm.historyList.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.pageNumber++;
            vm.getHistoryList();
        }else{
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};